<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<script type="text/javascript">
	jQuery.ajax({
		type : 'GET',
		url : '/ManEnv/pgroup/list/json',
		dataType : 'json',
		success : function(groups) {
			for (i in groups){
			    var gEntry = $('<li class="dropdown-submenu"><a href="javascript:void()" >' 
			    		+ groups[i].name + '</a></li>');
			    if(groups[i].projects != null){
			    	var subEntry = $('<ul class="dropdown-menu"></ul>');
				    for (j in groups[i].projects){
				    	//subEntry.append('<li><a href="javascript:void(0)" onclick=getProjectInfo(' + groups[i].projects[j].id + ')>'
				    	//		 + groups[i].projects[j].name + '</a></li>');
				    	subEntry.append('<li><a href="/ManEnv/project/list/' + groups[i].projects[j].id + '">'
                                + groups[i].projects[j].name + '</a></li>');
				        
				    }
				    gEntry.append(subEntry).appendTo("#project-header-menu");
			    }
			}
			
		},
		error : function() {
			alert("error!");
		}
	});
	
	$(document).ready(function(){

	});

	
	function getProjectInfo(projectId){
		$.ajax({
	        type : 'GET',
	        url : '/ManEnv/project/list/' + projectId,
            async : false,  //同步请求  
            timeout:1000,  
            success:function(project){
                d = new dTree('d');
                //level 0
                d.add(0, -1, project.name);
                //level 1
                d.add(1, 0, '架构定义','#', '','xxx',''); 
                d.add(2, 0, '设计模式','#', '','',''); 
                //level 3 
                d.add(3, 1, '系统架构实例','/ManEnv/aadl/template/select'); 
                d.add(4, 1, 'AADL文档',''); 
                //level 3
                d.add(5, 2, '实体数据区','/ManEnv/entityZone/'+ project.id + '/list');
                d.add(6, 2, '总线通信','/ManEnv/project/' + project.id + '/design_pattern_component/BUS'); 
                d.add(7, 2, 'IO通信','/ManEnv/project/' + project.id + '/design_pattern_component/IO');  
                d.add(8, 2, '信息显示','/ManEnv/project/' + project.id + '/design_pattern_component/DISPLAY'); 
                d.add(9, 2, '控制响应','/ManEnv/project/' + project.id + '/design_pattern_component/CONTROL'); 
                d.closeAll();
            	$("#project-menu-tree").html(d.toString())
                
            },  
            error: function() {  
                alert("ERROR!");
            }  
	    });
	}
	function jumpTo(url){
		jQuery.ajax({  
             type : "GET",  
             async : false,  //同步请求  
             url : url,  
             timeout:1000,  
             success:function(groups){  
            	 jQuery("#working-area").html(groups);//要刷新的div  
             },  
             error: function() {  
                 alert("ERROR!");
             }  
         });  
	}
</script>

<div class="navbar navbar-fixed-top">
	<div class="navbar-inner">
		<div class="container" >
			<button type="button" class="btn btn-navbar" data-toggle="collapse"
				data-target=".nav-collapse">
				<span class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="brand" href="javascript:void(0);" style="float:left;margin-left:-50px">CDSF座舱显控系统管理环境</a>
			<div class="nav-collapse collapse">
				<p class="navbar-text pull-right">
					<shiro:authenticated> 您好，<a href="javascript:void(0);" class="navbar-link"><shiro:principal type="cn.edu.sjtu.se.dslab.auth.CommonVariableModel" property="user"/></a><%-- &nbsp;&nbsp;&nbsp;<a href="<%=request.getContextPath()%>/logout" class="navbar-link">退出</a> --%></shiro:authenticated>
					<shiro:notAuthenticated>请<a href="<%=request.getContextPath()%>/login" class="navbar-link">登录!</a></shiro:notAuthenticated> 
					<a href="<%=request.getContextPath()%>/home" class="navbar-link" style="margin-left:50px"><i class="icon-home"></i>&nbsp;首页</a>
				</p>
				<shiro:authenticated>
				<ul class="nav">
				    <li class="dropdown">
				        <a href="#" class="dropdown-toggle" data-toggle="dropdown">项目<b class="caret"></b></a>
                        <ul class="dropdown-menu" id="project-header-menu">
                        	<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">新建</a>
                                <ul class="dropdown-menu">
                                	<shiro:hasAnyRoles name="Admin">
	                                    <li><a tabindex="-1"
	                                        href="javascript:void(0)" onclick="jumpTo('/ManEnv/pgroup/addPGroups')">项目类别</a>
	                                    </li>
                                    </shiro:hasAnyRoles>
                                    <li><a tabindex="2"
                                        href="javascript:void(0)" onclick="jumpTo('/ManEnv/project/addProjects')">项目</a>
                                    </li>
                                </ul>
                            </li>
                            
                            <li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">项目管理</a>
                                <ul class="dropdown-menu">
                                	<shiro:hasAnyRoles name="Admin">
                                    <li><a tabindex="-1"
                                        href="javascript:void(0)" onclick="jumpTo('/ManEnv/pgroup/list')">管理项目类别</a>
                                    </li>
                                    </shiro:hasAnyRoles>
                                    <li><a tabindex="2"
                                        href="javascript:void(0)" onclick="jumpTo('/ManEnv/project/list')">管理项目</a>
                                    </li>
                                </ul>
                            </li>
                            
                            <li class="divider"></li>
                        </ul>
                    </li>
                    </shiro:authenticated>
                    <shiro:hasAnyRoles name="Architector">
                    <li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">架构模板<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="<%=request.getContextPath()%>/aadl/template">管理架构模板</a></li>
							<li><a href="<%=request.getContextPath()%>/aadl/template/edit">定义架构模板</a></li>
						</ul>
					</li>
                    </shiro:hasAnyRoles>
					<shiro:hasAnyRoles name="Designer">
                    <li class="dropdown"><a href="#" class="dropdown-toggle"
                        data-toggle="dropdown">显控设计模式<b class="caret"></b></a>
                        <ul class="dropdown-menu">
                           <!--  <li><a href="javascript:void(0)" onclick="jumpTo('/ManEnv/project/manageDesignPatternCategory')">管理设计模式组件</a></li>
                            <li><a href="javascript:void(0)" onclick="jumpTo('/ManEnv/project/addDesignPatternCategory')">新建设计模式组件</a></li> -->
                            <li><a href="/ManEnv/designPatternCategory/list" >管理设计模式组件</a></li>
                            <li><a href="/ManEnv/designPatternCategory/addDesignPatternCategory" ">新建设计模式组件</a></li>
                        </ul>
                    </li>
                    </shiro:hasAnyRoles>
                    
					<shiro:hasAnyRoles name="Designer">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">功能函数组件<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">功能函数组件</a>
								<ul class="dropdown-menu">
									<li><a tabindex="-1"
										href="<%=request.getContextPath()%>/component/method_component">查看/检索</a>
									</li>
									<li><a tabindex="2"
										href="<%=request.getContextPath()%>/component/method_component/add">添加</a>
									</li>
								</ul>
							</li>
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">接口</a>
								<ul class="dropdown-menu">
									<li><a tabindex="1"
										href="<%=request.getContextPath()%>/interface">查看/检索</a>
									</li>
									<li><a tabindex="2"
										href="<%=request.getContextPath()%>/interface/add">添加</a>
									</li>
								</ul>
							</li>
						</ul>
					</li>
					</shiro:hasAnyRoles>  
					<shiro:hasRole name="DomainExpert">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">领域实体<b class="caret"></b></a>
						<ul class="dropdown-menu">
						<li><a tabindex="1" href="<%=request.getContextPath()%>/component/data_component">查看/检索</a></li>
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">数据实体</a>
								<ul class="dropdown-menu">
									<li><a tabindex="-1"
										href="<%=request.getContextPath()%>/domain_entity/data">查看/检索</a>
									</li>
									<li><a tabindex="2"
										href="<%=request.getContextPath()%>/domain_entity/data/add">添加</a>
									</li>
								</ul>
							</li>
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">类型实体</a>
								<ul class="dropdown-menu">
									<li><a tabindex="1"
										href="<%=request.getContextPath()%>/domain_entity/type">查看/检索</a>
									</li>
									<li><a tabindex="2"
										href="<%=request.getContextPath()%>/domain_entity/type/add">添加</a>
									</li>
								</ul>
							</li>
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">航电设备</a>
								<ul class="dropdown-menu">
									<li><a tabindex="1"
										href="<%=request.getContextPath()%>/domain_entity/equipment">查看/检索</a>
									</li>
									<li><a tabindex="2"
										href="<%=request.getContextPath()%>/domain_entity/equipment/add">添加</a>
									</li>
								</ul>
							</li>
							<li class="divider"></li>
							<li class="dropdown-submenu"><a tabindex="1" href="javascript:void(0);">航电设备类别</a>
								<ul class="dropdown-menu">
									<li><a tabindex="1"
										href="<%=request.getContextPath()%>/domain_entity/equipment/category/list">查看</a>
									</li>
									<li><a tabindex="1"
										href="<%=request.getContextPath()%>/domain_entity/equipment/category/add">添加</a>
									</li>
								</ul>
							</li>
						</ul>
					</li>
				    </shiro:hasRole>  
				    <shiro:hasRole name="Admin">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">用户管理<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="<%=request.getContextPath()%>/user/search">检索用户</a></li>
							<li><a href="<%=request.getContextPath()%>/user/list">用户列表</a></li>
						</ul>
					</li>
					</shiro:hasRole>
					<shiro:authenticated>
						<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">个人信息<b class="caret"></b></a>
							<ul class="dropdown-menu">
								<li><a href="<%=request.getContextPath()%>/user/info">个人资料</a></li>
								<li><a href="<%=request.getContextPath()%>/user/update/password">修改密码</a></li>
								<li class="divider">
								<li><a href="<%=request.getContextPath()%>/logout">退出</a></li>
							</ul>
						</li>
					</shiro:authenticated>
				</ul>
			</div>
			<!--/.nav-collapse -->
		</div>
	</div>
</div>
</div>